<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>实时电子时钟</title>
  <style>
    .box {
      width: 300px;
      height: 200px; 
      background-color: rgb(42, 48, 64);
      margin: 50px auto;
    }

    .time {
      height: 100px;
      width: 100%;
      color: white;
      font-size: 60px;
      font-weight: 600;
      text-align: center;
      line-height: 100px;
    }

    .date {
      height: 50px;
      width: 100%;
      color: white;
      text-align: center;
      letter-spacing: 2px;
      line-height: 50px; 
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="time"></div>
    <div class="date"></div>
  </div>
  <script>
    const day = [ '日','一', '二', '三', '四', '五', '六'];

    setInterval(function () {
      const date = new Date();
      let nowHours = date.getHours();
      const nowMinutes = date.getMinutes();
      let nowSecond = date.getSeconds();
      const nowYear = date.getFullYear();

      nowHours = nowHours < 10 ? '0' + nowHours : nowHours;
      nowSecond = nowSecond < 10 ? '0' + nowSecond : nowSecond;

          document.querySelector('.time').innerHTML = `${nowHours}:${nowMinutes}:${nowSecond}`;
    }, 1000);

    setInterval(function () {
      const date = new Date();
      const nowMonth = date.getMonth() + 1; 
      const nowDate = date.getDate();
      const nowDay = date.getDay();
      const nowYear = date.getFullYear();
            document.querySelector('.date').innerHTML = `${nowYear}年${nowMonth}月${nowDate}日&nbsp星期${day[nowDay%7]}`;
    }, 1000);
  </script>
</body>

</html>